
package me.zhengjie.rest;

import me.zhengjie.annotation.Log;
import me.zhengjie.domain.AppEventCate;
import me.zhengjie.service.AppEventCateService;
import me.zhengjie.service.dto.AppEventCateQueryCriteria;
import org.springframework.data.domain.Pageable;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

/**
* @website https://el-admin.vip
* @author IQW
* @date 2022-07-03
**/
@RestController
@RequiredArgsConstructor
@Api(tags = "事件分类管理")
@RequestMapping("/api/appEventCate")
public class AppEventCateController {

    private final AppEventCateService appEventCateService;

    @Log("导出数据")
    @ApiOperation("导出数据")
    @GetMapping(value = "/download")
    @PreAuthorize("@el.check('appEventCate:list')")
    public void exportAppEventCate(HttpServletResponse response, AppEventCateQueryCriteria criteria) throws IOException {
        appEventCateService.download(appEventCateService.queryAll(criteria), response);
    }

    @GetMapping
    @Log("查询事件分类")
    @ApiOperation("查询事件分类")
    @PreAuthorize("@el.check('appEventCate:list')")
    public ResponseEntity<Object> queryAppEventCate(AppEventCateQueryCriteria criteria, Pageable pageable){
        return new ResponseEntity<>(appEventCateService.queryAll(criteria,pageable),HttpStatus.OK);
    }

    @PostMapping
    @Log("新增事件分类")
    @ApiOperation("新增事件分类")
    @PreAuthorize("@el.check('appEventCate:add')")
    public ResponseEntity<Object> createAppEventCate(@Validated @RequestBody AppEventCate resources){
        return new ResponseEntity<>(appEventCateService.create(resources),HttpStatus.CREATED);
    }

    @PutMapping
    @Log("修改事件分类")
    @ApiOperation("修改事件分类")
    @PreAuthorize("@el.check('appEventCate:edit')")
    public ResponseEntity<Object> updateAppEventCate(@Validated @RequestBody AppEventCate resources){
        appEventCateService.update(resources);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    @DeleteMapping
    @Log("删除事件分类")
    @ApiOperation("删除事件分类")
    @PreAuthorize("@el.check('appEventCate:del')")
    public ResponseEntity<Object> deleteAppEventCate(@RequestBody Integer[] ids) {
        appEventCateService.deleteAll(ids);
        return new ResponseEntity<>(HttpStatus.OK);
    }
}